package sunsun.xiaoli.jiarebang.device;

import android.Manifest;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.pondteam.base.BaseActivity;

import com.itboye.pondteam.interfaces.PermissionListener;
import com.itboye.pondteam.utils.loadingutil.MAlert;
import sunsun.xiaoli.jiarebang.R;
import sunsun.xiaoli.jiarebang.app.App;
import sunsun.xiaoli.jiarebang.custom.RatioImageView;
import sunsun.xiaoli.jiarebang.utils.DeviceType;

import java.util.List;

import static sunsun.xiaoli.jiarebang.utils.LocationEnabled.locationProviderEnable;

/**
 * Created by Mr.w on 2017/3/4.
 * 此界面为通用界面
 */

public class ActivityStepFirst extends BaseActivity {
    TextView txt_title;
    ImageView img_back, img_right;
    Button btn_next;
    RatioImageView img;
    App app;
    TextView txt_description;

    //用于摄像头绑定的设备did
    String aq_did;
    DeviceType deviceType;
    public static ActivityStepFirst instance;

    public static ActivityStepFirst getInstance() {
        return instance;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_device_step1);
        instance = this;
        app = (App) getApplication();
        app.addDeviceFirst = this;
        deviceType = (DeviceType) getIntent().getSerializableExtra("device");
        aq_did = getIntent().getStringExtra("aq_did");
        txt_title.setText(getString(R.string.add) +getIntent().getStringExtra("title"));
        img.setBackgroundResource(deviceType.getSmartConfigBg());
        txt_description.setText(Html.fromHtml(deviceType.getSmartTips()));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_next:
                //android 9.0以上需要开启定位权限以及定位开关
                if (Build.VERSION.SDK_INT >= 28) {
                    if (!locationProviderEnable(this)) {
                        MAlert.alert(getStringValue(R.string.location_switch_closed));
                        return;
                    }
                }
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
                    requestRuntimePermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, new PermissionListener() {
                        @Override
                        public void granted() {
                            nextStep();
                        }

                        @Override
                        public void denied(List<String> deniedList) {
                            MAlert.alert(getStringValue(R.string.location_permission_denied));
                        }
                    });
                } else {
                    nextStep();
                }
                break;
        }

    }

    private void nextStep() {
        Intent intent = new Intent(this, ActivityInputWifiAndPass.class);
        intent.putExtra("aq_did", aq_did == null ? "" : aq_did);
        intent.putExtra("device", deviceType);
        startActivity(intent);
    }



//        switch (deviceType) {
//            case DEVICE_AQ806:
//                break;
//            case DEVICE_AQ500:
//                img.setBackgroundResource(R.drawable.smart_500);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_smart_500)));
//                break;
//            case DEVICE_AQ700:
//                img.setBackgroundResource(R.drawable.smart_700);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_smart_ph)));
//                break;
//            case DEVICE_AQ640:
//                img.setBackgroundResource(R.drawable.device_aq_640);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_smart_600)));
//                break;
//            case DEVICE_AQ680:
//                img.setBackgroundResource(R.drawable.smart_aq680);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_smart_680)));
//                break;
//            case DEVICE_AQ610:
////                img.setBackgroundResource(R.drawable.smart_aq610);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_smart_680)));
//                break;
//            case DEVICE_AQ118:
//                break;
//            case DEVICE_AQ600:
//                img.setBackgroundResource(R.drawable.smart_aq600);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_smart_600)));
//                break;
//            case DEVICE_JIAREBANG:
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_jiarebang)));
//                img.setBackgroundResource(R.drawable.add_jiarebangnew);
//                break;
//            case DEVICE_PH:
//                img.setBackgroundResource(R.drawable.smart_ph);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_smart_ph)));
//                break;
//            case DEVICE_SHUIBENG:
//                break;
//            case DEVICE_GUOLVTONG:
//                img.setBackgroundResource(R.drawable.pondteam_smartconfig);
//                break;
//            case DEVICE_CAMERA:
//            case DEVICE_CAMERA_NEW:
//                img.setBackgroundResource(R.drawable.smart_shexiangtou);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_shexiangtou)));
//                break;
//            case DEVICE_SHUIZUDENG:
//                img.setBackgroundResource(R.drawable.smart_light);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_smart_light)));
//                break;
//            case DEVICE_QIBENG:
//                break;
//            case DEVICE_WEISHIQI:
//                img.setBackgroundResource(R.drawable.smart_weishiqi);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_weishiqi)));
//                break;
//            case DEVICE_POND_FEEDER:
//                img.setBackgroundResource(R.drawable.smart_pond_feeder);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_weishiqi)));
//                break;
//            case DEVICE_HEW_FISHBOWL:
//                img.setBackgroundResource(R.drawable.smart_hew_fishbowl);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip_jiarebang)));
//                break;
//            case DEVICE_PET_DRINK://饮水机
//                img.setBackgroundResource(R.drawable.smart_pet_drink);
//                txt_description.setText(Html.fromHtml(getResources().getString(R.string.smartconfig_tip)));
//                break;
//        }
}
